/**
 * Created by pc on 2017/3/30.
 */

import React from "react";

import Pagination from "./Pagination";
import "./css/homePage.css"
export default class UserTable extends React.Component{

    constructor(props){
        super(props);
        this.state={

            /*后台错误提示*/
            hint:"",
            //起始时间
            timeBefore:"",
            //结束时间
            timeAfter:"",
            //列表数组
            orderCensusList:[],
            /*总共多少条*/
            total: 0,

        };
    }

    /*日期格式化*/
    dateFormat(time){
        if(time){
            let zero=(n)=>{
                return n = n>=0&&n<10 ? "0"+n : n;
            };
            let y = new Date(time).getFullYear();
            let m = new Date(time).getMonth()+1;
            let d = new Date(time).getDate();
            let h = new Date(time).getHours();
            let ms = new Date(time).getMinutes();

            return zero(y)+"-"+zero(m)+"-"+zero(d);
        }
    }


    addItem() {

        if(this.state.orderCensusList.length == 0){
            //alert("获取到的数据为空！");
            return(
                <tr  >
                    <td>
                        没有找到相关信息！
                    </td>
                </tr>
            );
        }
        return this.state.orderCensusList.map((item, index) => {
            return (
                <tr key={index + "_"}>
                    <td>{this.dateFormat(item.dateTime)}</td>
                    <td>{item.orderIncrease}</td>
                    <td>{item.orderUnfinished}</td>
                    <td>{item.orderFinished}</td>
                </tr>
            )
        })
    }

    onSure(size, num) {
        this.props.orderCensuByDate(size, num);
    }

    //asdasdasd23123123
    render() {
        return (
            <div>
                <div>
                    <table className="settle_rec_table recharge_recCom_table">
                        <thead>
                        <tr>
                            {
                                ["日期","新增订单","未结算订单(所有)","已结算订单(当天)"].map((item,index)=>
                                    <th key={index}>
                                        {item}
                                    </th>
                                )
                            }
                        </tr>
                        </thead>

                        <tbody>
                        {
                            this.addItem()
                        }
                        </tbody>
                    </table>
                    {/*页码*/}
                    <Pagination eachSize={10} dataSize={this.state.total} onSure={this.onSure.bind(this)}
                     ref={'pagination'}/>
                </div>
            </div>
        )
    }



}